//
//  RoomInfoView.swift
//  HinsLive
//
//  Created by haoxian on 2019/5/1.
//  Copyright © 2019 Hins. All rights reserved.
//

import UIKit
import RxSwift
import RxCocoa

class RoomInfoView: UIView {

    private lazy var headerLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 22, weight: .medium)
        label.text = "直播间"
        label.textAlignment = .center
        return label
    }()
    
    private lazy var roomTitleLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 15)
        label.text = "标题"
        return label
    }()
    
    private(set) lazy var roomTitleTF: UITextField = {
        let tf = UITextField()
        tf.backgroundColor = .colorWith(240, 240, 240)
        tf.layer.cornerRadius = 5
        tf.layer.masksToBounds = true
        tf.leftView = UILabel(frame: CGRect(x: 0, y: 0, width: 10, height: 30))
        tf.leftViewMode = .always
        tf.contentVerticalAlignment = .center
        return tf
    }()
    
    private lazy var roomTypeLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 15)
        label.text = "类型"
        label.textAlignment = .left
        return label
    }()
    
    private(set) lazy var roomTypeTitleView: PageTitleView = {
        var style = PageTitleStyle()
        style.common.backgroundColor = .white
        style.common.splitLineColor = .white
        style.coverView.color = .standardColor
        style.item.normalColor = .black
        style.item.selectedColor = .white
        return PageTitleView(titles: titles, style: style)
    }()
    
    private(set) lazy var cancelBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.backgroundColor = .roomGrayBackgroundColor
        btn.setImage(R.image.room_btn_close(), for: .normal)
        btn.setImage(R.image.room_btn_close(), for: .highlighted)
        btn.layer.cornerRadius = 12
        btn.layer.masksToBounds = true
        return btn
    }()
    
    private(set) lazy var submitBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.layer.cornerRadius = 5
        btn.layer.masksToBounds = true
        btn.backgroundColor = .standardColor
        btn.setTitleColor(.white, for: .normal)
        btn.setTitle("确认", for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        btn.alpha = 0.8
        btn.isEnabled = false
        return btn
    }()
    
    let titles: [String]
    
    init(titles: [String]) {
        self.titles = titles
        super.init(frame: .zero)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

private extension RoomInfoView {
    func setupUI() {
        
        backgroundColor = .white
        layer.cornerRadius = 10
        
        addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { (make) in
            make.width.height.equalTo(24)
            make.top.equalTo(5)
            make.right.equalToSuperview().offset(-5)
        }
        addSubview(headerLabel)
        headerLabel.snp.makeConstraints { (make) in
            make.left.top.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
            make.height.equalTo(36)
        }
        addSubview(roomTitleLabel)
        roomTitleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(headerLabel.snp.bottom).offset(10)
            make.right.left.equalTo(headerLabel)
            make.height.equalTo(20)
        }
        addSubview(roomTitleTF)
        roomTitleTF.snp.makeConstraints { (make) in
            make.top.equalTo(roomTitleLabel.snp.bottom).offset(10)
            make.right.left.equalTo(headerLabel)
            make.height.equalTo(30)
        }
        addSubview(roomTypeLabel)
        roomTypeLabel.snp.makeConstraints { (make) in
            make.top.equalTo(roomTitleTF.snp.bottom).offset(20)
            make.right.left.equalTo(headerLabel)
            make.height.equalTo(20)
        }
        addSubview(roomTypeTitleView)
        roomTypeTitleView.snp.makeConstraints { (make) in
            make.top.equalTo(roomTypeLabel.snp.bottom).offset(5)
            make.left.right.equalToSuperview()
            make.height.equalTo(40)
        }
        addSubview(submitBtn)
        submitBtn.snp.makeConstraints { (make) in
            make.top.equalTo(roomTypeTitleView.snp.bottom).offset(20)
            make.centerX.equalToSuperview()
            make.height.equalTo(35)
            make.width.equalTo(100)
        }
    }
}
